package com.example.myapplication;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.base.core.EmptyUtils;
import com.base.core.ui.BaseCallback;
import com.base.core.ui.BaseDialog;
import com.hjq.toast.ToastUtils;

import static com.example.myapplication.NotificationMonitorService.allpakage;


public class AddDialog extends BaseDialog {
    BaseCallback callback;

    public AddDialog(@NonNull Context context) {
        super(context, Gravity.CENTER);
    }

    @Override
    protected void initView() {

        final EditText edt_post = findViewById(R.id.edt_post);
        TextView tv_add = findViewById(R.id.tv_add);
        tv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String pakege = edt_post.getText().toString();
                if (EmptyUtils.isEmpty(pakege)) {
                    ToastUtils.show("请输入包名");
                    return;
                }
                if(allpakage.contains(pakege)){
                    ToastUtils.show("已经监听了该包名");
                    return;
                }
                allpakage.add(pakege);
                if (callback != null) {
                    callback.response(0);
                }
                dismiss();
            }
        });


    }

    public BaseCallback getCallback() {
        return callback;
    }

    public void setCallback(BaseCallback callback) {
        this.callback = callback;
    }

    @Override
    protected int getContentView() {
        return R.layout.dialog_add;
    }
}
